package org.iabako.client.ui.form.business.report;

import com.google.gwt.dom.client.InputElement;
import com.google.gwt.uibinder.client.UiFactory;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import org.iabako.client.tools.Messages;
import org.iabako.client.ui.layout.field.Button;
import org.iabako.client.user.AuthenticateUserProvider;
import org.iabako.shared.dto.ReportGenerationInputDTO;
import org.iabako.shared.entity.enumeration.TrackingType;

/**
 * Created by jose on 27/01/15.
 */
public abstract class AbstractReportForm extends Composite {

    public DisclosurePanel disclosurePanel;
    public com.google.gwt.user.client.ui.Button disclosureButton;

    @UiField
    protected Button generateReportAction;
    @UiField
    protected FormPanel generateForm;
    @UiField
    protected InputElement reportGeneratorFileToken;

    protected ReportGenerationInputDTO reportGenerationInputDTO = new ReportGenerationInputDTO();

    @UiFactory
    public DisclosurePanel createPanel() {
        HorizontalPanel newHeader = new HorizontalPanel();
        disclosureButton = new com.google.gwt.user.client.ui.Button(Messages.getLabel("report_generate_this"));
        disclosureButton.setStyleName("disclosurepanelbutton reportdisclosurepanelbutton");
        newHeader.add(disclosureButton);
        disclosurePanel = new DisclosurePanel();
        disclosurePanel.setHeader(newHeader);

        return disclosurePanel;
    }

    @Override
    protected void onLoad() {
        generateForm.addSubmitHandler(new FormPanel.SubmitHandler() {
            public void onSubmit(FormPanel.SubmitEvent submitEvent) {
                AuthenticateUserProvider.getTrackingPanel().refresh(TrackingType.reportGenerate);
            }
        });
    }
}
